package com.hugong.yxx.wksp.common.bean;


import com.alibaba.fastjson.JSON;
import lombok.Data;

import java.io.Serializable;

@Data
public class AccessToken implements Serializable {

    private static final long serialVersionUID = 6986530164134648944L;
    private String access_token;
    private String expires_in;
    private String refresh_token;
    private String openid;
    private String scope;

    /*public AccessToken(Response res, String typeid) throws Exception{
        super(res);
        JSONObject json =res.asJSONObject();
        try{
            accessToken = json.getString("access_token");
            expireIn = json.getString("expires_in");
            try {
                refreshToken = json.getString("refresh_token");
                uid = json.getString(typeid);
            } catch (Exception e) {
                refreshToken = null;
                uid = null;
            }
        } catch (JSONException je) {
            throw new Exception(je.getMessage() + ":" + json.toString(), je);
        }
    }
     "access_token":"ACCESS_TOKEN",
    "expires_in":7200,
    "refresh_token":"REFRESH_TOKEN",
    "openid":"OPENID",
    "scope":"SCOPE"


    */
    public AccessToken(Response response) {
        AccessToken accessToken = JSON.parseObject(response.getBody(), AccessToken.class);
        this.openid = accessToken.openid;
        this.access_token = accessToken.access_token;
        this.expires_in = accessToken.expires_in;
        this.refresh_token = accessToken.refresh_token;
        this.scope = accessToken.scope;
    }
}
